package com.jprocms.module.cms.dal.mysql.investigateoptionop;

import com.jpro.framework.common.pojo.PageResult;
import com.jpro.framework.mybatis.core.mapper.BaseMapperX;
import com.jpro.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.jprocms.module.cms.controller.admin.investigateoptionop.vo.InvestigateOptionOpListReqVO;
import com.jprocms.module.cms.controller.admin.investigateoptionop.vo.InvestigateOptionOpPageReqVO;
import com.jprocms.module.cms.dal.dataobject.investigateoptionop.InvestigateOptionOpDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.lang.Nullable;

import java.util.List;

/**
 * 问卷调查选项与调查意见关联 Mapper
 *
 * @author jprocms
 */
@Mapper
public interface InvestigateOptionOpMapper extends BaseMapperX<InvestigateOptionOpDO> {


    /**
     * 根据调查问卷选项ID列表删除数据
     *
     * @param optionIds 调查问卷选项ID列表
     */
    int deleteByOptionIds(List<Long> optionIds);

    /**
     * 删删除属于某调查问卷条目ID，且不包含的相应调查问卷选项id列表的数据
     *
     * @param itemId    调查问卷条目ID
     * @param optionIds 不包含的调查选项id列表
     * @return 被删除的数据条数
     */
    int deleteByItemId(@Param("itemId") Long itemId, @Param("optionIds") List<Long> optionIds);

    /**
     * 根据调查意见ID删除数据
     *
     * @param opinionId 调查意见ID
     */
    int deleteByOpinionId(@Param("opinionId") Long opinionId);

    /**
     * 根据调查问卷ID删除数据
     *
     * @param surveyId 调查问卷ID
     * @param itemIds  不包含的调查条目d列表
     * @return 被删除的数据条数
     */
    int deleteByInvestigateId(@Param("investigateId") Long investigateId, @Param("itemIds") List<Long> itemIds);

    /**
     * 根据用户ID删除数据
     *
     * @param userId 用户ID
     * @return 被删除的数据条数
     */
    int deleteByUserId(@Param("userId") Long userId);

    /**
     * 根据站点ID删除数据
     *
     * @param siteId 站点ID
     * @return 被删除的数据条数
     */
    int deleteBySiteId(@Param("siteId") Long siteId);

    /**
     * 根据主键获取数据
     *
     * @param id 主键ID
     * @return 实体对象。没有找到数据，则返回 {@code null}
     */
    @Nullable
    InvestigateOptionOpDO select(Long id);

    default PageResult<InvestigateOptionOpDO> selectPage(InvestigateOptionOpPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InvestigateOptionOpDO>()
                .eqIfPresent(InvestigateOptionOpDO::getInvestigateOpinionId, reqVO.getInvestigateOpinionId())
                .eqIfPresent(InvestigateOptionOpDO::getInvestigateId, reqVO.getInvestigateId())
                .eqIfPresent(InvestigateOptionOpDO::getInvestigateItemId, reqVO.getInvestigateItemId())
                .eqIfPresent(InvestigateOptionOpDO::getInvestigateOptionId, reqVO.getInvestigateOptionId())
                .betweenIfPresent(InvestigateOptionOpDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InvestigateOptionOpDO::getId));
    }

    default List<InvestigateOptionOpDO> selectList(InvestigateOptionOpListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<InvestigateOptionOpDO>()
                .eqIfPresent(InvestigateOptionOpDO::getInvestigateOpinionId, reqVO.getInvestigateOpinionId())
                .eqIfPresent(InvestigateOptionOpDO::getInvestigateId, reqVO.getInvestigateId())
                .eqIfPresent(InvestigateOptionOpDO::getInvestigateItemId, reqVO.getInvestigateItemId())
                .eqIfPresent(InvestigateOptionOpDO::getInvestigateOptionId, reqVO.getInvestigateOptionId())
                .betweenIfPresent(InvestigateOptionOpDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InvestigateOptionOpDO::getId));
    }

}
